export default class BaseEditPage {
  constructor() {
    let config = {
      // components: {
      // },
      // props: {},
      datas: {
        taskDefKey: '',
        title: ''
      },
      //title切换
      activated() {
        if (this.titles?.length) { this.title = this.titles[this.editModel] }
      },
      mounted() {
        if (this.titles?.length) { this.title = this.titles[this.editModel] }
      },
      created() {
        let to = this.$route // 当前路由
        // console.log(to)
        // 若路由params存在则缓存
        // if (JSON.stringify(to.query) != '{}') {
        //   sessionStorage.setItem(to.name, JSON.stringify(to.query))
        // }
        // 合并params到vue实例的data
        // Object.assign(this,JSON.parse(sessionStorage.getItem(to.name)))
        Object.assign(this, to.query)
      },
      methods: {
        /**
         * 删除草稿:api 请求api;params 请求参数
         */
        handleRemove() {
          this.$confirm({
            title: '温馨提示',
            content: '确定删除草稿？',
            onOk: () => {
              return this.removeApi?.remove({ id: this.id }).then(() => {
                this.$message.success('删除成功！')
                // 关闭当前页
                this.$multiTab.close()
              })
            },
          })
        },
        /**
         * 提交二次确认
         */
        handleSecondSub(data) {
          this.$confirm({
            title: '温馨提示',
            content: '请确认是否要提交?',
            onOk: () => {
              return this.update(data).then((res) => {
                if (res.code == 200 || res.code == 0) {
                  this.$message.success('提交成功')
                  // 关闭当前页
                  this.$multiTab.close()

                } else {
                  this.loading = false

                }
              })
            },
          })
        },
        /**
         * 动态关闭
         */
        handleActiveClose() {
          this.isBack ? this.$router.go(-1) : (this.businessId ? window.close() : this.$multiTab.close())
        },
        /**
         * 判断业务详情中的组件是否需要显示
         */
        checkVisibleInDetail() {
          let { checkVisibleInDetail } = require('@/utils/util')
          return checkVisibleInDetail(this)
        },
        /**
         * 获取打印内容
         */
        getPritContent(templateCode, type = 'quality') {
          let { print } = require(`@/api/quality/${type}`) // api
          return print.getList({
            id: this.printId || this.id,
            templateCode: templateCode,
          }).then((res) => {
            if (res.data.content) {
              return res.data.content
            }
          })
        },
      }
      // beforeDestroy() {
      //   let to = this.$route // 当前路由
      //   // 组件销毁前删除缓存
      //   sessionStorage.removeItem(to.name)
      // },
    }
    config.data = function () {
      return config.datas
    }
    return config
  }
}
